home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWGadgts / Sources / FWView.cpp < prev   
Encoding:
Text File  |  1995-11-08  |  41.4 KB  |  1,267 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWView.cpp
  4. //    Release Version:    $ 1.0d10 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWVIEW_H
  13. #include "FWView.h"
  14. #endif
  15.  
  16. #ifndef FWFRAME_H
  17. #include "FWFrame.h"
  18. #endif
  19.  
  20. #ifndef FWEVENT_H
  21. #include "FWEvent.h"
  22. #endif
  23.  
  24. #ifndef FWSCROLR_H
  25. #include "FWScrolr.h"
  26. #endif
  27.  
  28. #ifndef FWSELECT_H
  29. #include "FWSelect.h"
  30. #endif
  31.  
  32. #ifndef FWPRESEN_H
  33. #include "FWPresen.h"
  34. #endif
  35.  
  36. #ifndef FWODGEOM_H
  37. #include "FWODGeom.h"
  38. #endif
  39.  
  40. #ifndef FWWINDOW_H
  41. #include "FWWindow.h"
  42. #endif
  43.  
  44. #ifndef FWCURSOR_H
  45. #include "FWCursor.h"
  46. #endif
  47.  
  48. #ifndef SOM_ODFrame_xh
  49. #include <Frame.xh>
  50. #endif
  51.  
  52. #ifndef SOM_ODShape_xh
  53. #include <Shape.xh>
  54. #endif
  55.  
  56. //========================================================================================
  57. // Runtime Informations
  58. //========================================================================================
  59.  
  60. #if FW_LIB_EXPORT_PRAGMAS
  61. #pragma lib_export on
  62. #endif
  63.  
  64. #ifdef FW_BUILD_MAC
  65. #pragma segment fwview
  66. #endif
  67.  
  68. //========================================================================================
  69. // CLASS FW_CView
  70. //========================================================================================
  71.  
  72. FW_DEFINE_CLASS_M1(FW_CView, FW_MEventHandler)
  73.  
  74. //----------------------------------------------------------------------------------------
  75. // FW_CView::FW_CView
  76. //----------------------------------------------------------------------------------------
  77. FW_CView::FW_CView(Environment* ev, FW_CView* container, 
  78.                     ODID theID, FW_Boolean enabled, FW_Priority thePriority,
  79.                     const FW_CRect& bounds, const FW_CPoint& extent, 
  80.                     FW_CScroller* scroller, 
  81.                     int contentSpace) :
  82.     FW_MEventHandler(ev, theID, container, enabled, thePriority),
  83.     fParentView(container),
  84.     fSubViews(NULL),
  85.     fBounds(bounds),
  86.     fScroller(scroller),
  87.     fAdorners(NULL),
  88.     fVisible(TRUE),
  89.     fIsContentView(FALSE),
  90.     fViewContentToFrameTransform(NULL),
  91.     fViewToFrameTransform(NULL),
  92.     fViewContentToViewTransform(NULL),
  93.     fContentSpaceSpecifier(contentSpace)
  94. {
  95.     fExtent = (extent == FW_kZeroPoint) ? fBounds.Size() : extent;
  96.  
  97.     // add new view to the parent's SubView list
  98.     fParentView->AddSubView(ev, this);
  99.  
  100.     // if view scrolls with content add it to the frame's list of scrolling views
  101.     if (UseContentSpaceInX(ev) || UseContentSpaceInY(ev)) {
  102.         GetFrame(ev)->AddScrollingView(ev, this);
  103.     }
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107. // FW_CView::FW_CView
  108. //----------------------------------------------------------------------------------------
  109.  
  110. FW_CView::FW_CView(Environment* ev, FW_CView* container, const FW_CRect& bounds, const FW_CPoint& extent, 
  111.                     FW_CScroller* scroller, int contentSpace) :
  112.     FW_MEventHandler(ev, 0, container, TRUE, kNoPriority),
  113.     fParentView(container),
  114.     fSubViews(NULL),
  115.     fBounds(bounds),
  116.     fScroller(scroller),
  117.     fAdorners(NULL),
  118.     fVisible(TRUE),
  119.     fIsContentView(FALSE),
  120.     fViewContentToFrameTransform(NULL),
  121.     fViewToFrameTransform(NULL),
  122.     fViewContentToViewTransform(NULL),
  123.     fContentSpaceSpecifier(contentSpace)
  124. {
  125.     fExtent = (extent == FW_kZeroPoint) ? fBounds.Size() : extent;
  126.  
  127.     // add new view to the parent's SubView list
  128.     fParentView->AddSubView(ev, this);
  129.     
  130.     // if view scrolls with content add it to the frame's list of scrolling views
  131.     if (UseContentSpaceInX(ev) || UseContentSpaceInY(ev)) {
  132.         GetFrame(ev)->AddScrollingView(ev, this);
  133.     }
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. // FW_CView::FW_CView
  138. //----------------------------------------------------------------------------------------
  139.  
  140. FW_CView::FW_CView(Environment* ev) :
  141.     FW_MEventHandler(),
  142.     fParentView(NULL),
  143.     fSubViews(NULL),
  144.     fScroller(NULL),
  145.     fAdorners(NULL),
  146.     fVisible(TRUE),
  147.     fIsContentView(FALSE),
  148.     fViewContentToFrameTransform(NULL),
  149.     fViewToFrameTransform(NULL),
  150.     fViewContentToViewTransform(NULL),
  151.     fContentSpaceSpecifier(0)
  152. {
  153.     // this ctor should be used by CFrame only, the only CView with a NULL fParentView
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // FW_CView::~FW_CView
  158. //----------------------------------------------------------------------------------------
  159.  
  160. FW_CView::~FW_CView()
  161. {
  162.     Environment *ev = somGetGlobalEnvironment();
  163.  
  164.     if (fScroller) {
  165.         delete fScroller;
  166.         fScroller = NULL;
  167.     }
  168.  
  169.     if (fSubViews)
  170.     {
  171.         FW_CView* view;
  172.         while ((view = (FW_CView*)fSubViews->Last()) != NULL) {
  173.             delete view;    // deleting a view remove itself from its parentView
  174.         }
  175.         delete fSubViews;
  176.         fSubViews = NULL;
  177.     }
  178.     
  179.     if (fViewContentToFrameTransform) {    
  180.         fViewContentToFrameTransform->Release(ev);
  181.         fViewContentToFrameTransform = NULL;
  182.     }
  183.     
  184.     if (fViewToFrameTransform) {    
  185.         fViewToFrameTransform->Release(ev);
  186.         fViewToFrameTransform = NULL;
  187.     }
  188.     
  189.     if (fViewContentToViewTransform) {    
  190.         fViewContentToViewTransform->Release(ev);
  191.         fViewContentToViewTransform = NULL;
  192.     }
  193.  
  194.     // *LSD: fAdorners?
  195.     
  196.     if (fParentView != NULL)    
  197.         fParentView->RemoveSubView(ev, this);
  198.  
  199.     if (UseContentSpaceInX(ev) || UseContentSpaceInY(ev)) {
  200.         GetFrame(ev)->RemoveScrollingView(ev, this);
  201.     }
  202. }
  203.  
  204. //----------------------------------------------------------------------------------------
  205. // FW_CView::SetExtent
  206. //----------------------------------------------------------------------------------------
  207.  
  208. void FW_CView::SetExtent(Environment* ev, const FW_CPoint& extent)
  209. {
  210.     fExtent = extent;
  211.     
  212.     // ContentView must udpate the ODFrame's extent
  213.     if (fIsContentView) {
  214.         ODPoint odPoint = extent;
  215.         GetFrame(ev)->GetODFrame(ev)->ChangeContentExtent(ev, &odPoint);
  216.     }
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. // FW_CView::MakeContentView
  221. //----------------------------------------------------------------------------------------
  222.  
  223. void FW_CView::MakeContentView(Environment* ev)    
  224. {
  225.     FW_CFrame*    frame = GetFrame(ev);
  226.  
  227.     // Declare ContentView to the CFrame
  228.     frame->SetContentView(ev, this);
  229.     fIsContentView = TRUE;
  230.     
  231.     // Set the extent to the ODFrame's extent, or the view's bounds
  232.     ODPoint odPoint;
  233.     frame->GetODFrame(ev)->GetContentExtent(ev, &odPoint);    
  234.     if (odPoint.x == 0 && odPoint.y == 0) 
  235.         fExtent = fBounds.Size();
  236.     else
  237.         fExtent = odPoint;
  238. }
  239.  
  240. //----------------------------------------------------------------------------------------
  241. // FW_CView::AddSubView
  242. //----------------------------------------------------------------------------------------
  243.  
  244. void FW_CView::AddSubView(Environment* ev, const FW_CView *subview)
  245. {
  246.     if (fSubViews == NULL) {
  247.         fSubViews = new FW_CPrivOrderedCollection;
  248.     } 
  249.     else {
  250.         FW_ASSERT(fSubViews->Contains(this) == FALSE);    // [LSD] should have an Assert here?
  251.     }
  252.     
  253.     fSubViews->AddLast((FW_CView*) subview);
  254.     SubViewAdded(ev, subview);
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. // FW_CView::SubViewAdded
  259. //----------------------------------------------------------------------------------------
  260.  
  261. void FW_CView::SubViewAdded(Environment* ev, const FW_CView* subview)
  262. {
  263. }
  264.  
  265. //----------------------------------------------------------------------------------------
  266. // FW_CView::RemoveSubView
  267. //----------------------------------------------------------------------------------------
  268.  
  269. void FW_CView::RemoveSubView(Environment* ev, const FW_CView* subview)
  270. {
  271.     FW_ASSERT(fSubViews != NULL);
  272.     FW_ASSERT(fSubViews->Contains((FW_CView*)subview));
  273.     
  274.     fSubViews->Remove((FW_CView*)subview);
  275.     SubViewRemoved(ev, subview);
  276. }
  277.  
  278. //----------------------------------------------------------------------------------------
  279. // FW_CView::SubViewRemoved
  280. //----------------------------------------------------------------------------------------
  281.  
  282. void FW_CView::SubViewRemoved(Environment* ev, const FW_CView* subview)
  283. {
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. // FW_CView::Invalidate
  288. //----------------------------------------------------------------------------------------
  289.  
  290. void FW_CView::Invalidate(Environment* ev, const FW_CRect& rect)
  291. {
  292.     FW_CRect tempRect(rect);
  293.     ViewContentToFrame(ev, tempRect);
  294.     FW_CAcquiredODShape aqInvalidShape = ::FW_NewODShape(ev, tempRect);
  295.     GetFrame(ev)->GetODFrame(ev)->Invalidate(ev, aqInvalidShape, NULL);
  296. }
  297.  
  298. //----------------------------------------------------------------------------------------
  299. // FW_CView::Validate
  300. //----------------------------------------------------------------------------------------
  301.  
  302. void FW_CView::Validate(Environment* ev, const FW_CRect& rect)
  303. {
  304.     FW_CRect tempRect(rect);
  305.     ViewContentToFrame(ev, tempRect);
  306.     FW_CAcquiredODShape aqValidShape = ::FW_NewODShape(ev, tempRect);
  307.     GetFrame(ev)->GetODFrame(ev)->Validate(ev, aqValidShape, NULL);
  308. }
  309.  
  310. //----------------------------------------------------------------------------------------
  311. // FW_CView::Invalidate
  312. //----------------------------------------------------------------------------------------
  313.  
  314. void FW_CView::Invalidate(Environment* ev, ODShape* invalidShape)
  315. {
  316.     if (invalidShape == NULL)
  317.     {
  318.         FW_CRect bounds(FW_kZeroPoint, GetSize(ev));
  319.         ViewToViewContent(ev, bounds);
  320.         Invalidate(ev, bounds);
  321.     }
  322.     else
  323.     {
  324.         FW_CAcquiredODShape aqCopy = invalidShape->Copy(ev);
  325.         ViewContentToFrame(ev, aqCopy);
  326.         GetFrame(ev)->GetODFrame(ev)->Invalidate(ev, aqCopy, NULL);
  327.     }
  328. }
  329.  
  330. //----------------------------------------------------------------------------------------
  331. // FW_CView::Validate
  332. //----------------------------------------------------------------------------------------
  333.  
  334. void FW_CView::Validate(Environment* ev, ODShape* invalidShape)
  335. {
  336.     if (invalidShape == NULL)
  337.     {
  338.         FW_CRect bounds(FW_kZeroPoint, GetSize(ev));
  339.         ViewToViewContent(ev, bounds);
  340.         Validate(ev, bounds);
  341.     }
  342.     else
  343.     {
  344.         FW_CAcquiredODShape aqCopy = invalidShape->Copy(ev);
  345.         ViewContentToFrame(ev, aqCopy);
  346.         GetFrame(ev)->GetODFrame(ev)->Validate(ev, aqCopy, NULL);
  347.     }
  348. }
  349.  
  350. //----------------------------------------------------------------------------------------
  351. //    FW_CView::AdjustCursor
  352. //----------------------------------------------------------------------------------------
  353. // where is in frame coordinate
  354.  
  355. FW_Boolean FW_CView::AdjustCursor(Environment *ev, ODFacet* odFacet, const FW_CPoint& theMousePoint)
  356. {
  357.     // If I am the content view let the frame do the job first
  358.     if (fIsContentView)  return GetFrame(ev)->AdjustCursor(ev, odFacet, theMousePoint);
  359.     
  360.     return FALSE;
  361. }
  362.  
  363. //----------------------------------------------------------------------------------------
  364. // FW_CView::CountSubViews
  365. //----------------------------------------------------------------------------------------
  366.  
  367. unsigned long FW_CView::CountSubViews(Environment* ev) const
  368. {
  369.     return fSubViews == NULL ? 0 : fSubViews->Count();
  370. }
  371.  
  372. //----------------------------------------------------------------------------------------
  373. // FW_CView::IsSubViewOf
  374. //----------------------------------------------------------------------------------------
  375.  
  376. FW_Boolean FW_CView::IsSubViewOf(Environment* ev, const FW_CView &parentView) const
  377. {
  378.     return (fParentView->fSubViews == NULL ? FALSE : fParentView->fSubViews->Contains((FW_CView*)&this));
  379. }
  380.  
  381. //----------------------------------------------------------------------------------------
  382. // FW_CView::IsMouseWithin
  383. //----------------------------------------------------------------------------------------
  384. //    theMousePoint is in frame coordinate
  385.  
  386. FW_Boolean FW_CView::IsMouseWithin(Environment* ev, ODFacet* odFacet, const FW_CPoint& theMousePoint) const
  387. {
  388.     // We get a NULL facet when clicking outside a modal dialog box.
  389.     if (odFacet == NULL)
  390.         return FALSE;
  391.     
  392.     FW_CPoint where(theMousePoint);
  393.     FrameToView(ev, where);
  394.     
  395.     return FW_CRect(FW_kZeroPoint, GetSize(ev)).Contains(where);
  396. }
  397.  
  398. //----------------------------------------------------------------------------------------
  399. //    FW_CView::CreateSubViews
  400. //----------------------------------------------------------------------------------------
  401.  
  402. void FW_CView::CreateSubViews(Environment *ev)  
  403. {
  404. }
  405.  
  406. //----------------------------------------------------------------------------------------
  407. //    FW_CView::AdjustSubViews
  408. //----------------------------------------------------------------------------------------
  409.  
  410. void FW_CView::AdjustSubViews(Environment *ev)    
  411. {
  412. }
  413.  
  414. //----------------------------------------------------------------------------------------
  415. //     FW_CView::GetViewContaining
  416. //----------------------------------------------------------------------------------------
  417. //    Find the VISIBLE View containing a point (theMousePoint is in frame coordinate)
  418.  
  419. FW_CView* FW_CView::GetViewContaining(Environment* ev, 
  420.                                     ODFacet* odFacet, 
  421.                                     const FW_CPoint& theMousePoint)
  422. {
  423.     FW_CView* viewUnder = NULL;
  424.     
  425.     if (fVisible) {
  426.         FW_CViewIterator ite(ev, this);
  427.         for (FW_CView* subview = (FW_CView *) ite.First(ev);
  428.                  ite.IsNotComplete(ev) && !viewUnder; 
  429.                  subview = (FW_CView *) ite.Next(ev))
  430.         {
  431.             viewUnder = subview->GetViewContaining(ev, odFacet, theMousePoint);
  432.         }
  433.         
  434.         if (viewUnder == NULL)
  435.         {
  436.             if (IsMouseWithin(ev, odFacet, theMousePoint))
  437.                 viewUnder = this;
  438.         }
  439.     }    
  440.     return viewUnder;
  441. }
  442.  
  443. //----------------------------------------------------------------------------------------
  444. //     FW_CView::PrivGetEventHandlerContaining
  445. //----------------------------------------------------------------------------------------
  446. //    theMousePoint is in frame coordinate
  447.  
  448. FW_MEventHandler* FW_CView::PrivGetEventHandlerContaining(Environment* ev, 
  449.                                     ODFacet* odFacet, 
  450.                                     const FW_CPoint& theMousePoint)
  451. {
  452.     return GetViewContaining(ev, odFacet, theMousePoint);
  453. }
  454.  
  455. //----------------------------------------------------------------------------------------
  456. //     FW_CView::AddScrollBarScroller
  457. //----------------------------------------------------------------------------------------
  458.  
  459. void FW_CView::AddScrollBarScroller(Environment* ev, FW_CScrollBar* horzSB, 
  460.                                                      FW_CScrollBar* vertSB)
  461. {
  462.         if (fScroller) {
  463.             delete fScroller;
  464.             fScroller = NULL;
  465.         }
  466.                 
  467.         // create scroller
  468.         FW_CScroller* scroller = new FW_CScrollBarScroller(ev, this, horzSB, vertSB);
  469.         fScroller = scroller;
  470.         scroller->UpdateScrollParameters(ev, FALSE);    // We don't want to notify 
  471. }
  472.  
  473. //----------------------------------------------------------------------------------------
  474. // FW_CView::SetLocation
  475. //----------------------------------------------------------------------------------------
  476.  
  477. void FW_CView::SetLocation(Environment* ev, const FW_CPoint& location)
  478. {
  479.     FW_CPoint oldLocation = fBounds.TopLeft();
  480.     
  481.     if (oldLocation != location) 
  482.     {
  483.         fBounds.right = location.x + (fBounds.right - fBounds.left);
  484.         fBounds.bottom = location.y + (fBounds.bottom - fBounds.top);
  485.         fBounds.left = location.x;
  486.         fBounds.top = location.y;
  487.  
  488.         PrivInvalidateCachedTransforms(ev);
  489.         
  490.         // must offset the frame's internal transform when ContentView is moved
  491.         if (fIsContentView) 
  492.         {
  493.             FW_CAcquiredODTransform aqTransform = GetFrame(ev)->AcquireInternalTransform(ev, NULL);
  494.             ODPoint offset(location - oldLocation);
  495.             aqTransform->MoveBy(ev, &offset);            
  496.             GetFrame(ev)->ChangeInternalTransform(ev, aqTransform);
  497.             
  498.             GetFrame(ev)->PrivContentViewLocationChanged(ev);        
  499.         }
  500.         
  501.         LocationChanged(ev, oldLocation);    // used by gadgets on Windows
  502.     }
  503. }
  504.  
  505. //----------------------------------------------------------------------------------------
  506. // FW_CView::LocationChanged
  507. //----------------------------------------------------------------------------------------
  508.  
  509. void FW_CView::LocationChanged(Environment* ev, const FW_CPoint& oldLocation)
  510. {
  511. FW_UNUSED(oldLocation);
  512. }
  513.  
  514. //----------------------------------------------------------------------------------------
  515. // FW_CView::SetSize
  516. //----------------------------------------------------------------------------------------
  517.  
  518. void FW_CView::SetSize(Environment* ev, const FW_CPoint& size)
  519. {
  520.     FW_CPoint oldSize = fBounds.Size();
  521.     if (oldSize != size) {
  522.         fBounds.right = fBounds.left + size.x; 
  523.         fBounds.bottom = fBounds.top + size.y;
  524.         SizeChanged(ev, oldSize);        // used by gadgets on Windows
  525.     }
  526. }
  527.  
  528. //----------------------------------------------------------------------------------------
  529. // FW_CView::SizeChanged
  530. //----------------------------------------------------------------------------------------
  531.  
  532. void FW_CView::SizeChanged(Environment* ev, const FW_CPoint& oldSize)
  533. {
  534. FW_UNUSED(oldSize);
  535. }
  536.  
  537. //----------------------------------------------------------------------------------------
  538. // FW_CView::IsVisible
  539. //----------------------------------------------------------------------------------------
  540.  
  541. FW_Boolean FW_CView::IsVisible(Environment* ev) const
  542. {
  543.     // If my parent is not visible I am also not visible
  544.     return fVisible && (fParentView != NULL ? fParentView->IsVisible(ev) : TRUE);
  545. }
  546.  
  547. //----------------------------------------------------------------------------------------
  548. // FW_CView::PrivInvalidateCachedTransforms
  549. //----------------------------------------------------------------------------------------
  550.  
  551. void FW_CView::PrivInvalidateCachedTransforms(Environment* ev)
  552. {
  553.     FW_CViewIterator iter(ev, this);
  554.     for (FW_CView* subview = (FW_CView*)iter.First(ev); iter.IsNotComplete(ev); subview = (FW_CView*)iter.Next(ev))
  555.     {
  556.         subview->PrivInvalidateCachedTransforms(ev);
  557.     }
  558.  
  559.     if (fViewContentToFrameTransform)
  560.     {
  561.         fViewContentToFrameTransform->Release(ev);
  562.         fViewContentToFrameTransform = NULL;
  563.     }
  564.  
  565.     if (fViewToFrameTransform)
  566.     {
  567.         fViewToFrameTransform->Release(ev);
  568.         fViewToFrameTransform = NULL;
  569.     }
  570.  
  571.     if (fViewContentToViewTransform)
  572.     {
  573.         fViewContentToViewTransform->Release(ev);
  574.         fViewContentToViewTransform = NULL;
  575.     }
  576. }
  577.  
  578. //----------------------------------------------------------------------------------------
  579. // FW_CView::IsInContentView
  580. //----------------------------------------------------------------------------------------
  581.  
  582. FW_Boolean    FW_CView::IsInContentView(Environment* ev) const
  583. {
  584.     if (fIsContentView)
  585.         return TRUE;            
  586.     else if (IsFrame(ev))            
  587.         return FALSE;    // this is the CFrame but its fIsContentView was FALSE
  588.     else
  589.         return fParentView->IsInContentView(ev);
  590. }
  591.  
  592. //----------------------------------------------------------------------------------------
  593. // FW_CView::AcquireViewContentToViewTransform
  594. //----------------------------------------------------------------------------------------
  595. // returns the transform to convert view content coordinates to view coordinates
  596.  
  597. ODTransform* FW_CView::AcquireViewContentToViewTransform(Environment* ev) const
  598. {
  599.     FW_CView* self = (FW_CView*)this;
  600.     
  601.     if (fViewContentToViewTransform == NULL)
  602.     {
  603.         self->fViewContentToViewTransform = FW_CopyAndRelease(ev, AcquireViewContentToFrameTransform(ev));
  604.         FW_CAcquiredODTransform aqTransform = FW_CopyAndRelease(ev, AcquireViewToFrameTransform(ev));
  605.         aqTransform->Invert(ev);
  606.         self->fViewContentToViewTransform->PostCompose(ev, aqTransform);
  607.     }
  608.  
  609.     self->fViewContentToViewTransform->Acquire(ev);    
  610.     return fViewContentToViewTransform;
  611. }
  612.  
  613. //----------------------------------------------------------------------------------------
  614. // FW_CView::AcquireViewToFrameTransform
  615. //----------------------------------------------------------------------------------------
  616. // returns the transform to convert view coordinates to frame coordinates
  617.  
  618. ODTransform* FW_CView::AcquireViewToFrameTransform(Environment* ev) const
  619. {
  620.     FW_CView* self = (FW_CView*)this;
  621.     
  622.     if (fViewToFrameTransform == NULL)
  623.     {
  624.         FW_CPoint location = GetLocation(ev);
  625.         self->fViewToFrameTransform = ::FW_NewODTransform(ev, location);
  626.         
  627.         if (fParentView != NULL)
  628.         {
  629.             FW_CAcquiredODTransform aqViewContentTransform = fParentView->AcquireViewContentToFrameTransform(ev);
  630.             self->fViewToFrameTransform->PostCompose(ev, aqViewContentTransform);
  631.         }
  632.     }
  633.     
  634.     self->fViewToFrameTransform->Acquire(ev);    
  635.     return fViewToFrameTransform;
  636. }
  637.  
  638. //----------------------------------------------------------------------------------------
  639. // FW_CView::AcquireViewContentToFrameTransform
  640. //----------------------------------------------------------------------------------------
  641. // returns the transform to convert view content coordinates to frame coordinates
  642.  
  643. ODTransform* FW_CView::AcquireViewContentToFrameTransform(Environment* ev) const
  644. {
  645.     FW_CView* self = (FW_CView*)this;
  646.     
  647.     if (fViewContentToFrameTransform == NULL)
  648.     {
  649.         self->fViewContentToFrameTransform = FW_CopyAndRelease(ev, AcquireViewToFrameTransform(ev));
  650.         
  651.         if (IsContentView(ev) || UseContentSpaceInX(ev) || UseContentSpaceInY(ev))
  652.         {
  653.             ODPoint offset, internalOffset;
  654.             FW_CAcquiredODTransform aqInternalTransform = GetFrame(ev)->AcquireInternalTransform(ev, NULL);
  655.             aqInternalTransform->GetOffset(ev, &internalOffset);
  656.             
  657.             // ----- the location of the content view is already included in the Internal transform -----
  658.             FW_CPoint location = FW_kZeroPoint;
  659.             GetFrame(ev)->GetContentView(ev)->ViewToFrame(ev, location);    // gives me the location of the content view in frame coordinate
  660.  
  661.             // [LSD] need to handle scaling too
  662.             offset.x = (UseContentSpaceInX(ev) || IsContentView(ev)) ?  internalOffset.x - location.x.AsODFixed() : 0;
  663.             offset.y = (UseContentSpaceInY(ev) || IsContentView(ev)) ?  internalOffset.y - location.y.AsODFixed() : 0;
  664.                 
  665.             self->fViewContentToFrameTransform->MoveBy(ev, &offset);
  666.         }
  667.     }
  668.     
  669.     self->fViewContentToFrameTransform->Acquire(ev);
  670.  
  671.     return fViewContentToFrameTransform;
  672. }
  673.  
  674. //----------------------------------------------------------------------------------------
  675. //     FW_CView::FrameToViewContent
  676. //----------------------------------------------------------------------------------------
  677.  
  678. void FW_CView::FrameToViewContent(Environment *ev, FW_CPoint& point) const
  679. {
  680.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));    
  681.     point.InverseTransform(ev, aqViewToFrameTransform);
  682. }
  683.  
  684. void FW_CView::FrameToViewContent(Environment *ev, FW_CRect& rect) const
  685. {
  686.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));    
  687.     rect.InverseTransform(ev, aqViewToFrameTransform);
  688. }
  689.  
  690. void FW_CView::FrameToViewContent(Environment *ev, ODShape* shape) const
  691. {
  692.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));    
  693.     shape->InverseTransform(ev, aqViewToFrameTransform);
  694. }
  695.  
  696. //----------------------------------------------------------------------------------------
  697. //     FW_CView::ViewContentToFrame
  698. //----------------------------------------------------------------------------------------
  699.  
  700. void FW_CView::ViewContentToFrame(Environment *ev, FW_CPoint& point) const
  701. {
  702.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));        
  703.     point.Transform(ev, aqViewToFrameTransform);
  704. }
  705.  
  706. void FW_CView::ViewContentToFrame(Environment *ev, FW_CRect& rect) const
  707. {
  708.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));        
  709.     rect.Transform(ev, aqViewToFrameTransform);
  710. }
  711.  
  712. void FW_CView::ViewContentToFrame(Environment *ev, ODShape* shape) const
  713. {
  714.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));        
  715.     shape->Transform(ev, aqViewToFrameTransform);
  716. }
  717.  
  718. //----------------------------------------------------------------------------------------
  719. //     FW_CView::FrameToView
  720. //----------------------------------------------------------------------------------------
  721.  
  722. void FW_CView::FrameToView(Environment *ev, FW_CPoint& point) const
  723. {
  724.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));    
  725.     point.InverseTransform(ev, aqViewToFrameTransform);
  726. }
  727.  
  728. void FW_CView::FrameToView(Environment *ev, FW_CRect& rect) const
  729. {
  730.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));    
  731.     rect.InverseTransform(ev, aqViewToFrameTransform);
  732. }
  733.  
  734. void FW_CView::FrameToView(Environment *ev, ODShape* shape) const
  735. {
  736.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
  737.     shape->InverseTransform(ev, aqViewToFrameTransform);
  738. }
  739.  
  740. //----------------------------------------------------------------------------------------
  741. //     FW_CView::ViewToFrame
  742. //----------------------------------------------------------------------------------------
  743.  
  744. void FW_CView::ViewToFrame(Environment *ev, FW_CPoint& point) const
  745. {
  746.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));    
  747.     point.Transform(ev, aqViewToFrameTransform);
  748. }
  749.  
  750. void FW_CView::ViewToFrame(Environment *ev, FW_CRect& rect) const
  751. {
  752.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
  753.     rect.Transform(ev, aqViewToFrameTransform);
  754. }
  755.  
  756. void FW_CView::ViewToFrame(Environment *ev, ODShape* shape) const
  757. {
  758.     FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
  759.     shape->Transform(ev, aqViewToFrameTransform);
  760. }
  761.  
  762. //----------------------------------------------------------------------------------------
  763. //     FW_CView::ViewToViewContent
  764. //----------------------------------------------------------------------------------------
  765.  
  766. void FW_CView::ViewToViewContent(Environment *ev, FW_CPoint& point) const
  767. {
  768.     FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));    
  769.     point.InverseTransform(ev, aqViewContentToViewTransform);
  770. }
  771.  
  772. void FW_CView::ViewToViewContent(Environment *ev, FW_CRect& rect) const
  773. {
  774.     FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));    
  775.     rect.InverseTransform(ev, aqViewContentToViewTransform);
  776. }
  777.  
  778. void FW_CView::ViewToViewContent(Environment *ev, ODShape* shape) const
  779. {
  780.     FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));    
  781.     shape->InverseTransform(ev, aqViewContentToViewTransform);
  782. }
  783.  
  784. //----------------------------------------------------------------------------------------
  785. //     FW_CView::ViewContentToView
  786. //----------------------------------------------------------------------------------------
  787.  
  788. void FW_CView::ViewContentToView(Environment *ev, FW_CPoint& point) const
  789. {
  790.     FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));    
  791.     point.Transform(ev, aqViewContentToViewTransform);
  792. }
  793.  
  794. void FW_CView::ViewContentToView(Environment *ev, FW_CRect& rect) const
  795. {
  796.     FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));    
  797.     rect.Transform(ev, aqViewContentToViewTransform);
  798. }
  799.  
  800. void FW_CView::ViewContentToView(Environment *ev, ODShape* shape) const
  801. {
  802.     FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));    
  803.     shape->Transform(ev, aqViewContentToViewTransform);
  804. }
  805.  
  806. //----------------------------------------------------------------------------------------
  807. //     FW_CView::GetFrame
  808. //----------------------------------------------------------------------------------------
  809. FW_CFrame* FW_CView::GetFrame(Environment* ev) const
  810. {
  811.     FW_CView* container = GetParentView(ev);
  812.  
  813.     // a null ParentView means that it's a CFrame
  814.     return container ? container->GetFrame(ev) : (FW_CFrame*)this;
  815. }
  816.  
  817. //----------------------------------------------------------------------------------------
  818. //     FW_CView::SetContentSpaceInX
  819. //----------------------------------------------------------------------------------------
  820. void FW_CView::SetContentSpaceInX(Environment *ev, FW_Boolean bool)
  821. {
  822.     fContentSpaceSpecifier &= ~FW_CView::kXaxis;
  823.     if (bool) {
  824.         fContentSpaceSpecifier |= FW_CView::kXaxis;
  825.         GetFrame(ev)->AddScrollingView(ev, this);
  826.     }
  827.     else {
  828.         GetFrame(ev)->RemoveScrollingView(ev, this);
  829.     }
  830. }
  831.  
  832. //----------------------------------------------------------------------------------------
  833. //     FW_CView::SetContentSpaceInY
  834. //----------------------------------------------------------------------------------------
  835. void FW_CView::SetContentSpaceInY(Environment *ev, FW_Boolean bool)
  836. {
  837.     fContentSpaceSpecifier &= ~FW_CView::kYaxis;
  838.     if (bool) {
  839.         fContentSpaceSpecifier |= FW_CView::kYaxis;
  840.         GetFrame(ev)->AddScrollingView(ev, this);
  841.     }
  842.     else {
  843.         GetFrame(ev)->RemoveScrollingView(ev, this);
  844.     }
  845. }
  846.  
  847. //----------------------------------------------------------------------------------------
  848. //     FW_CView::SetContentSpaceInScale
  849. //----------------------------------------------------------------------------------------
  850. void FW_CView::SetContentSpaceInScale(Environment *ev, FW_Boolean bool)
  851. {
  852.     fContentSpaceSpecifier &= ~FW_CView::kScale;
  853.     if (bool) fContentSpaceSpecifier |= FW_CView::kScale;
  854. }
  855.  
  856. //----------------------------------------------------------------------------------------
  857. //    FW_CView::HandleSuspendResumeEvent
  858. //----------------------------------------------------------------------------------------
  859.  
  860. FW_Boolean FW_CView::HandleSuspendResumeEvent(Environment* ev, const FW_CSuspendResumeEvent& theSuspendResumeEvent)
  861. {
  862.     FW_Boolean handled = FALSE;
  863.     FW_CViewIterator ite(ev, this);
  864.     for (FW_CView* view = (FW_CView *) ite.First(ev);
  865.              ite.IsNotComplete(ev) && !handled; 
  866.              view = (FW_CView *) ite.Next(ev))
  867.     {
  868.         handled = view->HandleSuspendResumeEvent(ev, theSuspendResumeEvent);
  869.     }
  870.     
  871.     return handled ? TRUE
  872.                     : FW_MEventHandler::HandleSuspendResumeEvent(ev, theSuspendResumeEvent);
  873. }
  874.  
  875. //----------------------------------------------------------------------------------------
  876. //    FW_CView::HandleActivateEvent
  877. //----------------------------------------------------------------------------------------
  878.  
  879. FW_Boolean FW_CView::HandleActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
  880. {
  881.     FW_Boolean handled = FALSE;
  882.     FW_CViewIterator ite(ev, this);
  883.     for (FW_CView* view = (FW_CView *) ite.First(ev);
  884.              ite.IsNotComplete(ev) && !handled; 
  885.              view = (FW_CView *) ite.Next(ev))
  886.     {
  887.         handled = view->HandleActivateEvent(ev, theActivateEvent);
  888.     }
  889.     
  890.     return handled ? TRUE
  891.                    : FW_MEventHandler::HandleActivateEvent(ev, theActivateEvent);
  892. }
  893.  
  894. //----------------------------------------------------------------------------------------
  895. //     FW_CView::HandleMouseDown
  896. //----------------------------------------------------------------------------------------
  897.  
  898. FW_Boolean FW_CView::HandleMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  899. {
  900.     FW_CFrame* frame = GetFrame(ev);
  901.     FW_ASSERT(frame);
  902.  
  903.     FW_Boolean inActiveWindow = frame->GetWindow(ev)->IsActive(ev);
  904.  
  905.     FW_Boolean clickedInFrame = fIsContentView || !frame->IsRoot(ev);
  906.     if (frame->PrivActiveWindowOnMouseDown(ev, theMouseEvent.GetFacet(ev), clickedInFrame))
  907.         return TRUE;
  908.  
  909.     if (fIsContentView)
  910.     {
  911.         FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
  912.         if (selection)
  913.             selection->UpdateSelectionOnMouseDown(ev, theMouseEvent, NULL, FALSE, FALSE);
  914.     }
  915.     
  916.     if (inActiveWindow)
  917.     {
  918.         if (this->IsEnabled(ev) && this->WantsToBeTarget(ev))
  919.             this->BecomeTarget(ev);
  920.  
  921.         FW_MEventHandler::HandleMouseDown(ev, theMouseEvent);
  922.     }
  923.     
  924.     return TRUE;
  925. }
  926.  
  927. //----------------------------------------------------------------------------------------
  928. //    FW_CView::HandleMouseDownInEmbeddedFrameBorder
  929. //----------------------------------------------------------------------------------------
  930. //    Set the cursor to the closed hand
  931.  
  932. FW_Boolean FW_CView::HandleMouseDownInEmbeddedFrameBorder(Environment* ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
  933. {
  934.     FW_CFrame* frame = GetFrame(ev);
  935.     FW_ASSERT(frame);
  936.  
  937.     FW_gClosedHandCursor.Select();
  938.  
  939.     frame->ActivateFrame(ev, theBorderMouseEvent.GetFacet(ev));
  940.  
  941.     FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
  942.     if (selection)
  943.         selection->UpdateSelectionOnMouseDown(ev, 
  944.                                                 theBorderMouseEvent, 
  945.                                                 theBorderMouseEvent.GetEmbeddedFacet(ev), 
  946.                                                 TRUE, 
  947.                                                 FALSE);
  948.     
  949.     return FW_MEventHandler::HandleMouseDownInEmbeddedFrameBorder(ev, theBorderMouseEvent);
  950. }
  951.  
  952. //----------------------------------------------------------------------------------------
  953. // FW_CView::HandleMouseDownInEmbeddedFrame
  954. //----------------------------------------------------------------------------------------
  955.  
  956. FW_Boolean FW_CView::HandleMouseDownInEmbeddedFrame(Environment* ev, 
  957.                                                 const FW_CEmbeddedMouseEvent& theEmbeddedMouseEvent)
  958. {
  959.     FW_CFrame* frame = GetFrame(ev);
  960.     FW_ASSERT(frame);
  961.  
  962.     if (frame->PrivActiveWindowOnMouseDown(ev, theEmbeddedMouseEvent.GetFacet(ev), TRUE))
  963.         return TRUE;
  964.  
  965.     FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
  966.     if (selection)
  967.         selection->UpdateSelectionOnMouseDown(ev, 
  968.                                                 theEmbeddedMouseEvent, 
  969.                                                 theEmbeddedMouseEvent.GetEmbeddedFacet(ev), 
  970.                                                 FALSE,     // Not in active border
  971.                                                 FALSE);    // Not in Background
  972.  
  973.     return FW_MEventHandler::HandleMouseDownInEmbeddedFrame(ev, theEmbeddedMouseEvent);
  974. }
  975.  
  976. //----------------------------------------------------------------------------------------
  977. // FW_CView::HandleBGMouseDownInEmbeddedFrame
  978. //----------------------------------------------------------------------------------------
  979.  
  980. FW_Boolean FW_CView::HandleBGMouseDownInEmbeddedFrame(Environment* ev, 
  981.                                                 const FW_CEmbeddedMouseEvent& theEmbeddedMouseEvent)
  982. {
  983.     FW_CFrame* frame = GetFrame(ev);
  984.     FW_ASSERT(frame);
  985.  
  986.     FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
  987.     if (selection)
  988.         selection->UpdateSelectionOnMouseDown(ev, 
  989.                                                 theEmbeddedMouseEvent, 
  990.                                                 theEmbeddedMouseEvent.GetEmbeddedFacet(ev), 
  991.                                                 FALSE,     // Not in active border
  992.                                                 TRUE);    // In Background
  993.  
  994.     return FW_MEventHandler::HandleBGMouseDownInEmbeddedFrame(ev, theEmbeddedMouseEvent);
  995. }
  996.  
  997. //----------------------------------------------------------------------------------------
  998. //     FW_CView::HandleBGMouseDown
  999. //----------------------------------------------------------------------------------------
  1000.  
  1001. FW_Boolean FW_CView::HandleBGMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  1002. {
  1003.     FW_CFrame* frame = GetFrame(ev);
  1004.     FW_ASSERT(frame);
  1005.  
  1006.     FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
  1007.     if (selection)
  1008.         selection->UpdateSelectionOnMouseDown(ev, theMouseEvent, NULL, FALSE, TRUE);
  1009.     
  1010.     return FW_MEventHandler::HandleBGMouseDown(ev, theMouseEvent);
  1011. }
  1012.  
  1013. //----------------------------------------------------------------------------------------
  1014. //    FW_CView::DoBGMouseDown
  1015. //----------------------------------------------------------------------------------------
  1016.  
  1017. FW_Boolean FW_CView::DoBGMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
  1018. {
  1019.     FW_CFrame* frame = GetFrame(ev);
  1020.     FW_ASSERT(frame);
  1021.  
  1022.     FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
  1023.     if (selection != NULL && selection->IsMouseInDraggableItem(ev, frame, theMouseEvent, TRUE))
  1024.         return frame->Drag(ev, theMouseEvent);
  1025.     
  1026.     // return FALSE because I am not doing anything. Let the process manager do its job.
  1027.     return FALSE;     
  1028. }
  1029.  
  1030. //----------------------------------------------------------------------------------------
  1031. //     FW_CView::HandleMouseUp
  1032. //----------------------------------------------------------------------------------------
  1033.  
  1034. FW_Boolean FW_CView::HandleMouseUp(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  1035. {
  1036.     FW_CFrame* frame = GetFrame(ev);
  1037.     FW_ASSERT(frame);
  1038.  
  1039.     frame->ActivateFrame(ev, theMouseEvent.GetFacet(ev));    // Will test if it can be the activeframe
  1040.  
  1041.     return FW_MEventHandler::HandleMouseUp(ev, theMouseEvent);
  1042. }
  1043.  
  1044. //----------------------------------------------------------------------------------------
  1045. //    FW_CView::GetVisibleBounds
  1046. //----------------------------------------------------------------------------------------
  1047. //    Returns the visible bounds of the view through all its parent (in frame coordinate)
  1048.  
  1049. FW_CRect FW_CView::GetVisibleBounds(Environment *ev) const
  1050. {
  1051.     FW_CView* aView = (FW_CView*)this;
  1052.     FW_CRect visibleRect;
  1053.     while (aView != NULL)
  1054.     {
  1055.         FW_CRect bounds = aView->GetBounds(ev);
  1056.         bounds.Place(FW_kFixed0, FW_kFixed0);
  1057.         aView->ViewToFrame(ev, bounds);
  1058.  
  1059.         if (aView == this)
  1060.             visibleRect = bounds;
  1061.         else
  1062.             visibleRect.Intersection(bounds);
  1063.         
  1064.         aView = aView->GetParentView(ev);
  1065.     }
  1066.     
  1067.     return visibleRect;
  1068. }
  1069.  
  1070. //----------------------------------------------------------------------------------------
  1071. //    FW_CView::HandleDraw
  1072. //----------------------------------------------------------------------------------------
  1073. // invalidShape is in frame coordinate
  1074.  
  1075. void FW_CView::HandleDraw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  1076. {
  1077.     if (fVisible) {
  1078.         // [LSD] todo: Draw high-priority adorners
  1079.  
  1080.         FW_CAcquiredODShape aqInvalidShape;
  1081.         
  1082.         // Restricted the invalidShape to the view bounds intersected with all its parents
  1083.         if (invalidShape != NULL)        
  1084.         {
  1085.             aqInvalidShape = invalidShape->Copy(ev);
  1086.             
  1087.             FW_CRect visibleBounds = GetVisibleBounds(ev);
  1088.                         
  1089.             FW_CAcquiredODShape tempShape = ::FW_NewODShape(ev, visibleBounds);
  1090.             aqInvalidShape->Intersect(ev, tempShape);
  1091.             
  1092.             FrameToViewContent(ev, aqInvalidShape);
  1093.         }
  1094.  
  1095.         // Draw the view
  1096.         Draw(ev, odFacet, aqInvalidShape);
  1097.         
  1098.         // Draw its subviews
  1099.         FW_CViewIterator ite(ev, this);
  1100.         for (FW_CView* subview = ite.First(ev); ite.IsNotComplete(ev);  subview = ite.Next(ev))
  1101.         {
  1102.             subview->HandleDraw(ev, odFacet, invalidShape);
  1103.         }
  1104.     
  1105.         // [LSD] todo: Draw low-priority adorners
  1106.     }
  1107. }
  1108.  
  1109. //----------------------------------------------------------------------------------------
  1110. //    FW_CView::Draw
  1111. //----------------------------------------------------------------------------------------
  1112. //    invalidShape is in content coordinate of this view
  1113.  
  1114. void FW_CView::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  1115. {
  1116. FW_UNUSED(odFacet);
  1117. FW_UNUSED(invalidShape);
  1118. }
  1119.  
  1120. //----------------------------------------------------------------------------------------
  1121. //     FW_CView::Activate
  1122. //----------------------------------------------------------------------------------------
  1123.  
  1124. FW_Boolean FW_CView::Activate(Environment* ev)
  1125. {
  1126.     FW_Boolean result = FW_MEventHandler::Activate(ev);
  1127.     
  1128.     // [LSD] simple progagation of Activate to Subviews for now.
  1129.     FW_CViewIterator ite(ev, this);
  1130.     for (FW_CView* subview = ite.First(ev); ite.IsNotComplete(ev);  subview = ite.Next(ev))
  1131.     {
  1132.         subview->Activate(ev);
  1133.     }
  1134.     
  1135.     return result;
  1136. }
  1137.  
  1138. //----------------------------------------------------------------------------------------
  1139. //     FW_CView::Deactivate
  1140. //----------------------------------------------------------------------------------------
  1141.  
  1142. void FW_CView::Deactivate(Environment* ev)
  1143. {
  1144.     FW_MEventHandler::Deactivate(ev);
  1145.     
  1146.     // progagates Deactivate to Subviews 
  1147.     FW_CViewIterator ite(ev, this);
  1148.     for (FW_CView* subview = ite.First(ev); ite.IsNotComplete(ev);  subview = ite.Next(ev))
  1149.     {
  1150.         subview->Deactivate(ev);
  1151.     }
  1152. }
  1153.  
  1154. //----------------------------------------------------------------------------------------
  1155. // FW_CView::SetVisible
  1156. //----------------------------------------------------------------------------------------
  1157.  
  1158. void FW_CView::SetVisible(Environment* ev, FW_Boolean visible, FW_Boolean propagate)
  1159. {
  1160.     // Not allowed to make the Frame invisible!
  1161.     FW_ASSERT(IsFrame(ev) == FALSE || visible == TRUE);
  1162.     
  1163.     fVisible = visible;
  1164.     
  1165.     // Activate/Deactivate event handler
  1166.     if (visible)  {
  1167.         FW_MEventHandler::Activate(ev);
  1168.     } 
  1169.     else {
  1170.         FW_MEventHandler::Deactivate(ev);
  1171.     }
  1172.     
  1173.     // propagates to subviews
  1174.     if (propagate) {
  1175.         FW_CViewIterator ite(ev, this);
  1176.         for (FW_CView* subview = ite.First(ev); ite.IsNotComplete(ev);  subview = ite.Next(ev))
  1177.         {
  1178.             subview->SetVisible(ev, visible, TRUE);
  1179.         }    
  1180.     }
  1181. }
  1182.  
  1183. //========================================================================================
  1184. // CLASS FW_CViewContext
  1185. //========================================================================================
  1186.  
  1187. //----------------------------------------------------------------------------------------
  1188. // FW_CViewContext::FW_CViewContext
  1189. //----------------------------------------------------------------------------------------
  1190. // invalidShape should be in content coordinate of the view
  1191.  
  1192. FW_CViewContext::FW_CViewContext(Environment* ev, FW_CView *view, ODFacet* odFacet, ODShape* invalidShape) :
  1193.     FW_CGraphicContext(ev),
  1194.     fView(view),
  1195.     fFacet(odFacet),
  1196.     fTransform(NULL)
  1197. {
  1198.     fTransform = FW_CopyAndRelease(ev, view->AcquireViewContentToFrameTransform(ev));
  1199.     
  1200.     // compute fTransform to convert view to canvas coordinates 
  1201.     FW_CAcquiredODTransform aqFrameTransform = fFacet->AcquireFrameTransform(ev, NULL);
  1202.     fTransform->PostCompose(ev, aqFrameTransform);
  1203.     
  1204.     // Make a copy of the aggregate clip shape 
  1205.     FW_CAcquiredODShape aqClipShape = FW_CopyAndRelease(ev, odFacet->AcquireAggregateClipShape(ev, NULL));
  1206.     
  1207.     // Intersect it with the visible part of the view
  1208.     {
  1209.         FW_CRect visibleBounds = view->GetVisibleBounds(ev);
  1210.         FW_CAcquiredODShape visibleShape = ::FW_NewODShape(ev, visibleBounds);
  1211.         aqClipShape->Intersect(ev, visibleShape);
  1212.     }
  1213.     
  1214.     //    convert it to view content coordinates
  1215.     view->FrameToViewContent(ev, aqClipShape);
  1216.     
  1217.     // Intersect it with the invalidShape (already in view content coordinates)
  1218.     if (invalidShape != NULL)
  1219.         aqClipShape->Intersect(ev, invalidShape);
  1220.  
  1221.     InitGraphicContext(FW_CFacetPartInfo::GetFacetGraphicDevice(ev, fFacet), 
  1222.                         fTransform, 
  1223.                         aqClipShape);
  1224.  
  1225.     FW_END_CONSTRUCTOR
  1226. }
  1227.  
  1228. //----------------------------------------------------------------------------------------
  1229. // FW_CViewContext::~FW_CViewContext
  1230. //----------------------------------------------------------------------------------------
  1231.  
  1232. FW_CViewContext::~FW_CViewContext()
  1233. {
  1234.     FW_START_DESTRUCTOR
  1235.  
  1236.     if (fTransform)
  1237.         fTransform->Release(somGetGlobalEnvironment());
  1238. }
  1239.  
  1240. //========================================================================================
  1241. // CLASS FW_CViewIterator
  1242. //========================================================================================
  1243.  
  1244. //----------------------------------------------------------------------------------------
  1245. // FW_CViewIterator::FW_CViewIterator
  1246. //----------------------------------------------------------------------------------------
  1247.  
  1248. FW_CViewIterator::FW_CViewIterator(Environment* ev, const FW_CView *container) :
  1249.     fIterator(NULL)    
  1250. {
  1251.     if (container->fSubViews)
  1252.         fIterator = new FW_COrderedCollectionIterator(container->fSubViews);
  1253.  
  1254.     FW_END_CONSTRUCTOR
  1255. }
  1256.  
  1257. //----------------------------------------------------------------------------------------
  1258. // FW_CViewIterator::~FW_CViewIterator
  1259. //----------------------------------------------------------------------------------------
  1260.  
  1261. FW_CViewIterator::~FW_CViewIterator()
  1262. {
  1263.     FW_START_DESTRUCTOR
  1264.     
  1265.     delete fIterator;
  1266. }
  1267.